package com.yixia.framework.config;


import com.yixia.common.config.YiXiaConfig;
import com.yixia.common.constant.Constants;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.*;

/**
 * web项目配置类
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {


    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")
                .allowedOrigins("*")
                .allowCredentials(true)
                .allowedMethods("GET", "HEAD", "POST", "PUT", "DELETE", "OPTIONS")
                .allowedHeaders("*")/*允许请求头跨域*/
                .maxAge(3600);
    }


    /*网络请求虚拟路径映射*/
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        //registry.addResourceHandler("/image/userAvatar/**").addResourceLocations("file:F:\\重要资料\\java1234\\userAvatar\\");

        registry.addResourceHandler(Constants.RESOURCE_PREFIX + "/**")
                .addResourceLocations("file:" + YiXiaConfig.getProfile() + "/");//
    }



}